{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python38364bitbase2260977e3f9146528175652a9fb0768b",
   "display_name": "Python 3.8.3 64-bit ('base')"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "2.25"
     },
     "metadata": {},
     "execution_count": 1
    }
   ],
   "source": [
    "'''\n",
    "解释器就像一个简单的计算器一样：你可以在里面输入一个表达式然后它会写出答案。 表达式的语法很直接：运算符 +、-、*、/ 的用法和其他大部分语言一样（比如 Pascal 或者 C 语言）；括号 (()) 用来分组。比如:\n",
    "'''\n",
    "(1 + 2) * 3 / 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "1.6"
     },
     "metadata": {},
     "execution_count": 4
    }
   ],
   "source": [
    "8/5 # 除法得到的永远是浮点数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "1"
     },
     "metadata": {},
     "execution_count": 8
    }
   ],
   "source": [
    "'''\n",
    "整数（比如 2、4、20 ）的类型是 int，有小数部分的（比如 5.0、1.6 ）的类型是 float。 在这个手册的后半部分我们会看到更多的数字类型。\n",
    "\n",
    "除法运算 (/) 永远返回浮点数类型。如果要做 floor division 得到一个整数结果（忽略小数部分）你可以使用 // 运算符；如果要计算余数，可以使用 %\n",
    "'''\n",
    "8//5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "3"
     },
     "metadata": {},
     "execution_count": 10
    }
   ],
   "source": [
    "8%5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "42"
     },
     "metadata": {},
     "execution_count": 12
    }
   ],
   "source": [
    "8*5+2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "32"
     },
     "metadata": {},
     "execution_count": 13
    }
   ],
   "source": [
    "\n",
    "'''\n",
    "在Python中，可以使用 ** 运算符来计算乘方\n",
    "'''\n",
    "2 ** 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "900"
     },
     "metadata": {},
     "execution_count": 15
    }
   ],
   "source": [
    "'''\n",
    "等号 (=) 用于给一个变量赋值。然后在下一个交互提示符之前不会有结果显示出来:\n",
    "'''\n",
    "width = 20\n",
    "height = 5 * 9\n",
    "width * height"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "output_type": "error",
     "ename": "NameError",
     "evalue": "name 'n' is not defined",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-17-ab0680a89434>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mn\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name 'n' is not defined"
     ]
    }
   ],
   "source": [
    "'''\n",
    "如果一个变量未定义（未赋值），试图使用它时会向你提示错误:\n",
    "'''\n",
    "n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "14.0"
     },
     "metadata": {},
     "execution_count": 18
    }
   ],
   "source": [
    "'''\n",
    "Python中提供浮点数的完整支持；包含多种混合类型运算数的运算会把整数转换为浮点数:\n",
    "'''\n",
    "4 *3.75 -1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "4"
     },
     "metadata": {},
     "execution_count": 20
    }
   ],
   "source": [
    "\"\"\"\n",
    "_ 的使用： 在交互模式上可以储存上次计算的结果\n",
    "\"\"\"\n",
    "n = 1\n",
    "b = 3\n",
    "n + b "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "4\n"
    }
   ],
   "source": [
    "print(_)\n",
    "'''\n",
    "这个变量应该被使用者当作是只读类型。不要向它显式地赋值——你会创建一个和它名字相同独立的本地变量，它会使用魔法行为屏蔽内部变量。\n",
    "\n",
    "除了 int 和 float，Python也支持其他类型的数字，例如 Decimal 或者 Fraction。Python 也内置对 复数 的支持，使用后缀 j 或者 J 就可以表示虚数部分（例如 3+5j ）。\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}